﻿using AutoMapper;
using MediatR;
using NPOI.SS.Formula.Functions;
using SmartProduction.Domain.ProductionOrders;
using SmartProduction.Domain.Ptoduction;
using SmartProduction.ErrorCode;
using SmartProduction.Infarstructrue.Interface;
using SmartProduction.Read.API.Application.Commands.BasicList;

namespace SmartProduction.Read.API.Application.CommandHandlers.BasicListHandler
{
    public class zhijianBasicListCommandHandler : IRequestHandler<zhijianBasicListCommand, APIPaing<List<Basicinformation>>>
    {
        private readonly IMapper mapper;
        private readonly IBaseRepository<Basicinformation> repository;

        public zhijianBasicListCommandHandler(IMapper mapper, IBaseRepository<Basicinformation> repository)
        {
            this.mapper = mapper;
            this.repository = repository;
        }

        public async Task<APIPaing<List<Basicinformation>>> Handle(zhijianBasicListCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIPaing<List<Basicinformation>> result = new APIPaing<List<Basicinformation>>();
                var list = await repository.GetAll();
                result.data = list.ToList();
                result.Code = APIEnums.查询成功;
                result.Msg = APIEnums.查询成功.ToString();
                return await Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
